package com.nuc.bigdata.controller;

import com.nuc.bigdata.orm.dto.PhotoNewsDto;
import com.nuc.bigdata.orm.feign.PhotoNewsFeign;
import com.nuc.bigdata.service.PhotoNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;

/**
 * @author JackLuo
 * @date 2019/11/26
 */
@Api(value = "资讯controller")
@RestController
@RequestMapping("/oa-photos")
public class PhotoController {

    private final PhotoNewsService photoNewsService;

    @Autowired
    PhotoController(PhotoNewsService photoNewsService) {
        this.photoNewsService = photoNewsService;
    }

    /**
     * 获取所有资讯
     *
     * @return 资讯ArrayList
     */
    @ApiOperation(value = "获取所有图片资讯", notes = "提供给front服务", tags = "获取资讯接口")
    @GetMapping("/news")
    public ArrayList<PhotoNewsFeign> listNews() {
        return photoNewsService.listByMenuId(null);
    }

    /**
     * 获取指定菜单项下所有图片资讯
     *
     * @param menuId 菜单标识
     * @return 资讯ArrayList
     */
    @ApiOperation(value = "获取指定菜单下图片资讯", notes = "提供给front服务", tags = "获取资讯接口")
    @GetMapping("/news/menu/{menuId}")
    public ArrayList<PhotoNewsFeign> listNewsByMenuId(
            @ApiParam(value = "菜单唯一标识") @PathVariable("menuId") @NotEmpty String menuId) {
        return photoNewsService.listByMenuId(menuId);
    }

    /**
     * 获取指定资源信息
     *
     * @param pnId 图片资讯唯一标识
     * @return 资讯信息
     */
    @ApiOperation(value = "获取指定的图片资讯", notes = "提供给front服务", tags = "获取资讯接口")
    @GetMapping("/news/{pnId}")
    public PhotoNewsFeign queryNews(
            @ApiParam(value = "图片资讯唯一标识") @PathVariable("pnId") @NotEmpty String pnId) {
        return photoNewsService.queryByPnId(pnId);
    }

    /**
     * 创建图片新闻
     *
     * @param newsDto 图片新闻dto
     * @param userId  用户唯一标识
     */
    @ApiOperation(value = "创建图片资讯", notes = "提供给管理服务", tags = {"增删改资讯接口"})
    @PostMapping("/news")
    public void createPhotoNews(
            @ApiParam(value = "新闻资讯Dto", required = true) @RequestBody PhotoNewsDto newsDto,
            @ApiParam(value = "用户唯一标识") @RequestParam("userId") String userId) {
        photoNewsService.createPhotoNews(newsDto, userId);

    }

    /**
     * 修改图片文章
     *
     * @param pnId    文章唯一标识
     * @param newsDto 图片资讯dto
     * @param userId  用户唯一标识
     */
    @ApiOperation(value = "更新图片资讯信息", notes = "提供给管理服务", tags = {"增删改资讯接口"})
    @PutMapping("/news/{pnId}")
    public void updatePhotoNews(
            @ApiParam(value = "图片资讯唯一标识", required = true) @PathVariable("pnId") String pnId,
            @ApiParam(value = "图片资讯Dto", required = true) @RequestBody PhotoNewsDto newsDto,
            @ApiParam(value = "用户唯一标识", required = true) @RequestParam("userId") String userId) {
        photoNewsService.updatePhotoNews(pnId, newsDto, userId);
    }

    /**
     * 删除指定图片资讯
     *
     * @param pnId 图片资讯唯一标识
     */
    @ApiOperation(value = "删除图片资讯信息", notes = "提供给管理服务", tags = {"增删改资讯接口"})
    @DeleteMapping("/news/{pnId}")
    public void removePhotoNews(
            @ApiParam(value = "图片资讯唯一标识", required = true) @PathVariable("pnId") String pnId) {
        photoNewsService.removePhotoNews(pnId);
    }
}
